<template>
	<view class="wrap">
		<view class="left">
			<scroll-view scroll-y="true" class="scrLeft" >
				<view :class="['item',{'active':currentIndex==index}]" v-for="(item,index) in leftMenuTxt" :key="index" @click="handleCheck(index)">{{item}}</view>
			</scroll-view>
		</view>
		<view class="right">
			<scroll-view scroll-y="true">
				<view class="rightWrap" v-for="(item,index) in rightMenuTxt" :key="index">
					<view class="title">{{item.cate_name}}</view>
					<view class="main">
						<view class="mainItem" v-for="item1 in item.children" :key="item1.goods_id" @click="handleId(item1.goods_id)">
							<image :src="item1.cat_icon" mode="widthFix"></image>
							<text>{{item1.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {categories} from "../../static/js/categories.js"
	export default {
		data() {
			return {
				leftMenuTxt:[],
				currentIndex:0,
				rightMenuTxt:[]
			}
		},
		created() {
			this.leftMenuTxt = categories.map(v=>v.cat_name)
			this.rightMenuTxt = categories[this.currentIndex].children
		},
		methods: {
			handleCheck(index){
				this.currentIndex = index
				this.rightMenuTxt = categories[index].children
			},
			handleId(id){
				uni.navigateTo({
					url:"../deatil/deatil?goods_id="+id
				})
				console.log(id)
			}
			
		}
	}
</script>

<style lang="less">
	page{
		height: 100%;
	}
	.wrap{
		display: flex;
		height: 100%;
		.left{
			flex: 2;
			height: 100%;
			background-color: #efefef;
			.scrLeft{
				height: 100%;
				.item{
					line-height: 100rpx;
					display: flex;
					justify-content: center;
				}
				.active{
					border-right: 8rpx solid red;
				}
			}
		}
		.right{
			flex: 5;
			height: 100px;
			.rightWrap{
				padding: 20rpx;
				.main{
					display: flex;
					flex-wrap: wrap;
					.mainItem{
						width: 50%;
						image{
							width: 100%;
						}
					}
				}
			}
		} 
	}
</style>
